package sch.jl.caigou.impl;

import java.util.ArrayList;
import java.util.List;

import jiliang.purchase.demo.CriteriaTaiZhang;
import jiliang.purchase.demo.Tongjitaizhangdemo;
import sch.jl.caigou.dao.getTaiZhang;

public class getTaiZhangImpl extends DaoImpl<Tongjitaizhangdemo> implements getTaiZhang
{
	@Override
	public List<Tongjitaizhangdemo> getInfo(CriteriaTaiZhang CTZ, String[] title) {
		
		List<Tongjitaizhangdemo> list = new ArrayList<Tongjitaizhangdemo>();
		String sql = "";
		sql = getSql(CTZ,title);
		//System.out.println(sql);
		
		list = queryForList(sql);
		
		return list;
	}
	
	public String getSql(CriteriaTaiZhang CTZ, String[] title)
	{
		String sql="select ";
		for(int i=0;i<title.length;i++)
		{
			if(i!=title.length-1)
			{
				sql+=title[i]+",";
			}
			else
			{
				sql+=title[i]+" from think_lingxing_sbjj,think_shenqing,think_danwei where xm_id = '4' and think_lingxing_sbjj.sq_id = think_shenqing.sq_id and think_lingxing_sbjj.shiyongbm = think_danwei.dw_id";
			}
			
		}
		
		if(CTZ.getEndtime()==null && CTZ.getStatrtime()==null && CTZ.getXingming()==null && CTZ.getXmid() ==null && CTZ.getCaigoufs() == null && CTZ.getJinfeidm()==null && CTZ.getLast_lc() ==null && CTZ.getShenqingsj() == null)
		{
			return sql;
		}else
		{
			if(CTZ.getEndtime()!=null)
			{
				sql += " and sq_shijian <=" + "'" + CTZ.getEndtime() + "'";
			}
			if(CTZ.getStatrtime()!=null)
			{
				sql += " and sq_shijian >=" + "'" + CTZ.getStatrtime() + "'";
			}
			if(CTZ.getXingming()!=null)
			{
				sql += " and xingming =" + "'" + CTZ.getXingming() + "'";
			}
			if(CTZ.getCaigoufs()!=null)
			{
				sql += " and caigoufs like '%采购中心采购%'";
			}
			if(CTZ.getJinfeidm()!=null)
			{
				sql += " and jingfeidm =" + "'" + CTZ.getJinfeidm() + "'";
			}
			if(CTZ.getShenqingsj()!=null)
			{
				sql += " and think_lingxing_sbjj.shenqingsj =" + "'" + CTZ.getShenqingsj() + "'";
			}
			if(CTZ.getLast_lc()!=null)
			{
				if(CTZ.getLast_lc().equals("1"))
				{
					sql += " and think_shenqing.states = '1' or think_shenqing.states = '2'";
				}
				else
				{
					sql += " and think_shenqing.states = '3'";
				}
			}
		}
		return sql;
	}

}
